'Copyright 2006 James Downey

Imports System.Xml

Public Class Attribute

    '<!--

    '      attribute elements - used for selecting attributes from the
    '                      surrounding entity / link-entity, these
    '                      values are returned as part of the fetch

    '   -->
    '   <ElementType name='all-attributes' content='empty' model='closed' />
    '   <ElementType name='attribute' content='empty' model='closed'>
    '      <AttributeType name='name' dt:type='string' required='yes' />
    '      <!-- -->
    '      <attribute type='name' />
    '   </ElementType>
    '   <!--

    Public Name As String
    Public Aggregate As String = ""
    Public AttributeAlias As String = ""

    Public Sub New(ByVal Name As String)
        Me.Name = Name
    End Sub

    Public Sub New(ByVal AttributeNode As XmlNode)
        Me.New(AttributeNode.Attributes("name").Value)
        If Not AttributeNode.Attributes("aggregate") Is Nothing Then
            Me.Aggregate = AttributeNode.Attributes("aggregate").Value
        End If
        If Not AttributeNode.Attributes("alias") Is Nothing Then
            Me.AttributeAlias = AttributeNode.Attributes("alias").Value
        End If
    End Sub

    Public Overrides Function ToString() As String
        If Me.AttributeAlias.Length = 0 Then
            Return Me.Name
        Else
            Return Me.AttributeAlias
        End If
    End Function

    Public Function ToXML() As String
        Dim strXml As String
        strXml = "<attribute name='" & Me.Name & "' "
        If Me.AttributeAlias.Length > 0 Then
            strXml &= "alias='" & Me.AttributeAlias & "' "
        End If
        If Me.Aggregate.Length > 0 Then
            strXml &= "aggregate='" & Me.Aggregate & "'"
        End If
        strXml &= "/>"
        Return strXml
    End Function

End Class
